package com.flong.jxl;
import java.io.File;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class ReadWriteInfo1 {
	public static void main(String[] args)throws Exception {
		
		String path = "d:/pc_task/test.xls";	
		// 打开文件
		WritableWorkbook book1 = Workbook.createWorkbook(new File("D:/pc_task/湖北武汉_养生信息.xls "));
		// 生成名为“第一页”的工作表，参数0表示这是第一页
		WritableSheet sheet1 = book1.createSheet("第一页信息", 0);
		
		String titles [] = new String []{"店铺名","联系电话","店铺地址" };
		
		for (int i = 0; i < titles.length; i++) {
			Label labe1 = new Label(i, 0, titles[i]);//column,row,count
			sheet1.addCell(labe1);
		}
		
		
		Workbook book = Workbook.getWorkbook(new File(path));
		Sheet sheet = book.getSheet(2);
		int rows = sheet.getRows();
		for (int i = 0; i <rows; i++) {
			Cell cell = sheet.getCell(0, i);
			String text = cell.getContents().trim().replace("", "");
			if(text!=null && !"".equals(text)){
				
				String [] strArrays = text.split("=");
				String shopName= strArrays[0];
				String address= strArrays[1];
				String tels = strArrays[2];
				if(tels!=null && tels.contains("|")){
					String[] telArrays = tels.split("\\|");
					for (int j = 0; j < telArrays.length; j++) {
						//System.out.println(shopName+"="+telArrays[j]+"="+address);
						Label shopName1 = new Label(0, i + 1, shopName);
						Label tel = new Label(1, i + 1, telArrays[j]);
						Label address1 = new Label(2, i + 1, address);
						sheet1.addCell(shopName1);
						sheet1.addCell(tel);
						sheet1.addCell(address1);
					}
					
				}else{
					Label shopName1 = new Label(0, i + 1, shopName);
					Label tel = new Label(1, i + 1, tels);
					Label address1 = new Label(2, i + 1, address);
					sheet1.addCell(shopName1);
					sheet1.addCell(tel);
					sheet1.addCell(address1);
				}
			}
		}
		book1.write();
		book1.close();
		book.close();
		System.err.println("success");
	}
}